﻿using System;
using System.Collections.Generic;
using System.Linq;
using HiStaff.Base;
using HiStaff.Control;
using HiStaff.Domain;
using HiStaff.Util;
using HiStaff.Dal;
namespace HiStaff.iProfile
{
    public partial class Organization : FormBase
    {
        public Organization()
        {
            InitializeComponent();
        }
        protected override bool FormLoad()
        {
            try
            {
                base.AddBasicCommandBar();
                return base.FormLoad();
            }
            catch (Exception ex)
            {
                WriteErrorLog(ex);
                return false;
            }
        }
        protected override void ResetInputControl(System.Windows.Forms.Control container)
        {
            try
            {
                base.ResetInputControl(container);
                if (trvOrg.SelectedNode != null)
                {
                    lblParent.Text = trvOrg.SelectedNode.Text;
                }
            }
            catch (Exception ex)
            {
                WriteErrorLog(ex);
            }
        }
        protected override bool SaveButtonClick()
        {
            try
            {
                HiStaff.Domain.HU.HU_ORGANIZATION objUpdate = new Domain.HU.HU_ORGANIZATION();
                ValueControlsToObject(objUpdate, this);
                if (OracleHelper.ExcuteNonQuery("APRU_HU_ORGANIZATION", objUpdate))
                {
                    trvOrg.ReLoad();
                    return true;
                }
                else return false;
            }
            catch (Exception ex)
            {
                WriteErrorLog(ex);
                return false;
            }
        }
        protected override bool CancelButtonClick()
        {
            try
            {
                ValueObjectToControls(trvOrg.GetDataRowSelectedNote(), this);
                return true;
            }
            catch(Exception ex)
            {
                WriteErrorLog(ex);
                return false;
            }
        }
        protected override bool DeleteButtonClick()
        {
            try
            {
                if (OracleHelper.ExcuteNonQuery("APRD_HU_ORGANIZATION", trvOrg.GetDataRowSelectedNote()))
                {
                    trvOrg.ReLoad();
                    return true;
                }
                else return false;
            }
            catch(Exception ex)
            {
                WriteErrorLog(ex);
                return false;
            }
        }
        private void hiTreeOrganization1_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
        {
            ValueObjectToControls(trvOrg.GetDataRowSelectedNote(), this);
        }
    }
}
